home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Magazine / C_Tutorial / Part-4 / clip.c next >
C/C++ Source or Header  |  1997-08-31  |  2KB  |  61 lines

  1. /* clip.c and clip.h */
  2. /* A separate compilation unit for the clipping functions */
  3. /* In clip.h: declare public things (i.e., the functions) */
  4. /* In clip.c: make the actual definitions */
  5.  
  6. /* First of all, include our own header file, which will */
  7. /* declare our public functions */
  8. #include "clip.h"
  9.  
  10. #include<clib/graphics_protos.h>
  11. #include<clib/layers_protos.h>
  12.  
  13. /* Set a clip region on internal part of window */
  14. int setClipInternal(struct Window* win)
  15. {
  16.     /* Make a rectangle that describes the inside of the window */
  17.     struct Rectangle rect;
  18.   rect.MinX = win->BorderLeft;
  19.     rect.MinY = win->BorderTop;
  20.     rect.MaxX = win->Width - win->BorderRight - 1;
  21.     rect.MaxY = win->Height - win->BorderBottom - 1;
  22.     return setClipSized(win, &rect);
  23. }
  24.  
  25. /* Set a clip region on a specified part of window */
  26. int setClipSized(struct Window* win, struct Rectangle* size)
  27. {
  28.     /* Make a new region */
  29.     struct Region* reg;
  30.     if(reg = NewRegion())
  31.     {
  32.         /* Make the region equal to the size rectangle */
  33.         if(OrRectRegion(reg, size))
  34.         {
  35.             /* Set the clip region on the window's layer */
  36.             InstallClipRegion(win->WLayer, reg);
  37.             /* Say we succeeded */
  38.             return TRUE;
  39.         }
  40.         else
  41.         {
  42.             /* Failed to set region, so delete it */
  43.             DisposeRegion(reg);
  44.         }
  45.     }
  46.     /* If we get this far then we've failed */
  47.     return FALSE;
  48. }
  49.  
  50. /* Remove the clip region from a window */
  51. void removeClip(struct Window* win)
  52. {
  53.     struct Region* reg;
  54.     if(reg = InstallClipRegion(win->WLayer, NULL))
  55.     {
  56.         /* If a clip region is installed we assume it's our new one */
  57.         /* and so delete it */
  58.         DisposeRegion(reg);
  59.     }
  60. }
  61.